home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir30
/
alsps.zip
/
ALSP1.DOC
next >
Wrap
Text File
|
1993-11-04
|
4KB
|
137 lines
This is Lesson 1 of a series of AutoLISP training exercises given
on the CompuServe ADESK Forum by the Autodesk, Inc. Training
Department.
THE NAME OF THE LANGUAGE
Lisp stands for "list processing" or "list programming". In
Lisp, processing generally means "finding the value of an
object"; that is, processing is the method by which Lisp
determines the value of any expression, complex object, or simple
object.
OBJECTS
There are two general types of objects in AutoLISP - ATOMS and
LISTS. Atoms are simple objects; lists are complex objects.
Atoms and lists are mutually exclusive. Anything that is an
atom cannot be a list, and vice versa (there is one exception
that proves this rule, the object NIL; we'll examine it later).
ATOMS
Atoms can be integers, real numbers, text strings, AutoLISP
functions, symbols, or special objects that correspond to AutoCAD
entities, selection-sets, and files.
These are all atoms:
1 ;the integer 1
4.5 ;the real number 4.5
"A String of Pearls" ;a text string
setq ;an AutoLISP function
ename ;a user-defined symbol
See Section 1.4, "Lexical Conventions", of the R10 APR for more
information.
VALUES OF ATOMS
The value of any atom, except AutoLISP functions and user-defined
symbols, is itself. For example, the atom 1 has a value of 1;
the atom 4.5 has a value of 4.5; the atom "A String of Pearls"
has a value of "A String of Pearls".
You can determine the value of any atom at the AutoCAD command
prompt. Type an exclamation point "!" followed by the atom.
AutoLISP will find and return the value of the atom in the
command prompt area. For example, this expression finds the
value of the atom (and real number) 4.5:
Command: !4.5
4.5
LISTS
Lists are complex objects, referred to in some texts as symbolic
expressions, or "s-expressions". Lists are built out of atoms
and/or other lists. A list is syntactically simple; it must be
bounded by matching parentheses, and objects within the list must
be separated from one another by a space.
These are examples of lists:
(+ 1 3) ;add 1 and 3
(- 9 5) ;subtract 5 from 9
(+ 1 (+ 2 3)) ;add 1 to the result of adding 2 and 3
Anything bounded by matching parentheses must be a list; anything
not bounded by matching parentheses must be an atom.
ELEMENTS OF LISTS
The individual members of a list are known as its elements. This
is an example of a list with three elements, each an atom:
(+ 1 2)
Elements of lists may be either atoms or other lists. This is an
example of a list with three elements; two are atoms, one is
itself a list of three elements:
(+ 1 (+ 2 3))
| | \ /
| | \ /
| | |
elements
Elements of a list must be separated from one another by at least
one space. There is no limit on the number of spaces separating
elements, but there must be at least one. This is a perfectly
valid list:
(+ 1 (+ 1 3))
THE EMPTY LIST
There is one object in AutoLISP that is both an atom and a list.
It is the empty list; that is, a list of no elements, commonly
referred to as NIL.
() or nil
Nil (the empty list) in AutoLISP is "no value". When an object
in AutoLISP has no value, then the value of the object is nil.
EXERCISE
Which of these objects are atoms and which are lists?
1. 73.5
2. "0,0"
3. (1.0 2.0 3.0)
4. "String"
5. ("String")
6. ()
Find the values of these atoms at the AutoCAD command prompt.
1. 4.5
2. "text"
3. 17
4. setq
5. xyz
6. nil
How many elements are contained within each list?
1. (1.0 2.0 3.0)
2. (+ 1 2)
3. (+ 1 (+ 2 3))
4. (+ 1 2 (+ 3 4) 5)
5. (+ 1 (+ 2 (+ 3 4)) 5)
6. ()
Next week: Lists and Evaluation